#include "DiamondData.h"

int main()
{
  try {
    DiamondDataRow::register_dyntype();
    ifstream in("diamonds-dataset/4c.dat");
    //ifstream in("./4c.dat");
    vector<DiamondDataRow> drs;
    load_DiamonDataRow_file(in, &drs);
    cerr << "loaded " << drs.size() << " rows" << endl;
    
    DataSpace ds;
    ds.axes.add_axis<double>("weight");
    ds.axes.add_axis<CharN<1> >("color");
    ds.axes.add_axis<CharN<4> >("clarity");
    ds.axes.add_axis<CharN<3> >("cert");
    DynType* dt = DynTypeManager::get()->get_dyntype("DiamondDataRow");
    vector<data_index_t> max_shape(4);
    max_shape[0] = 500; max_shape[1] = 10; max_shape[2] = 10; max_shape[3] = 5;
    ds.create_datafield("diamonds.DS", dt, max_shape);
    
    for (size_t i = 0; i < drs.size(); i++) {
      const DiamondDataRow& ddr = drs[i];
      AxesCoor c(&ds.axes);
      c.set<double>("weight", ddr.weight);
      c.set<CharN<1> >("color", CharN<1>(ddr.color));
      c.set<CharN<4> >("clarity", CharN<4>(ddr.clarity));
      c.set<CharN<3> >("cert", CharN<3>(ddr.cert));
      c.print(cerr); cerr << " " << ddr.price;
      if (ds.is_none_at_coor(c)) {
	ds.set_value<DiamondDataRow>(c, ddr, true);
      } else {
	cerr << " dup"; 
      }
      cerr << endl;
    }
    ds.save();
  } catch (Error& e) {
    cerr << "Error caught: " << e.msg() << endl;
  }
}
